package com.evil.common.es.util;

import cn.hutool.core.collection.ListUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * ES 字段工具类
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
public class ESFieldUtil {

    public static final String POINT = ".";

    public static final String UNDERLINE = "_";

    public static final String KEYWORD = "keyword";

    public static String join(String... field) {
        return ESFieldUtil.join(Arrays.asList(field));
    }

    public static String joinKeyword(String... field) {
        List<String> fields = ListUtil.toList(field);
        fields.add(KEYWORD);
        return ESFieldUtil.join(fields);
    }

    public static String join(List<String> fields) {
        return StringUtils.join(fields, POINT);
    }

    public static String underJoin(String... field) {
        return ESFieldUtil.underJoin(Arrays.asList(field));
    }

    public static String underJoin(List<String> fields) {
        return StringUtils.join(fields, UNDERLINE);
    }
}
